﻿using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;
using MyFloridaHouse.LibDTO;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.DTO;

namespace MyFloridaHouse.DataAccess
{

    public partial class DAL_CensusData
    {

        /// <summary>
        /// [Obsolete] Updates the layer region.
        /// </summary>
        /// <param name="iLayerID">The i layer ID.</param>
        /// <param name="iRegionID">The i region ID.</param>
        /// <param name="iCenterLngX">The i center LNG X.</param>
        /// <param name="iCenterLatY">The i center lat Y.</param>
        /// <param name="iMapObject">The i map object.</param>
        /// <param name="iNorth">The i north.</param>
        /// <param name="iEast">The i east.</param>
        /// <param name="iSouth">The i south.</param>
        /// <param name="iWest">The i west.</param>
        /// <returns></returns>
        /// <remarks>[Obsolete] SPROC: usp_UpdateRegion</remarks>
        public List<SQLRegionDTO> UpdateLayerRegion(int iLayerID, int iRegionID, double iCenterLngX, double iCenterLatY, string iMapObject
                                                        , double iNorth, double iEast, double iSouth, double iWest)
        {
            List<SQLRegionDTO> itemList = new List<SQLRegionDTO>();

            string storedProcedureName = "usp_UpdateRegion";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("iLayerID", iLayerID);
                dataPartIDParm.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm2 = StoredProcedureCommand.Parameters.AddWithValue("iRegionID", iRegionID);
                dataPartIDParm2.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm3 = StoredProcedureCommand.Parameters.AddWithValue("iCenterLngX", iCenterLngX);
                dataPartIDParm3.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm4 = StoredProcedureCommand.Parameters.AddWithValue("iCenterLatY", iCenterLatY);
                dataPartIDParm4.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm5 = StoredProcedureCommand.Parameters.AddWithValue("iMapObject", iMapObject);
                dataPartIDParm5.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm6 = StoredProcedureCommand.Parameters.AddWithValue("iLatYmax", iNorth);
                dataPartIDParm6.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm7 = StoredProcedureCommand.Parameters.AddWithValue("iLngXmax", iEast);
                dataPartIDParm7.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm8 = StoredProcedureCommand.Parameters.AddWithValue("iLatYmin", iSouth);
                dataPartIDParm8.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm9 = StoredProcedureCommand.Parameters.AddWithValue("iLngXmin", iWest);
                dataPartIDParm9.Direction = ParameterDirection.Input;

                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(SQLRegionDTODataContract.DataContract(rdr));
                    }
                }
            }
            //Database db = Connect();
            //DbCommand dbCommand = db.GetStoredProcCommand("usp_UpdateRegion");
            //db.AddInParameter(dbCommand, "iLayerID", DbType.Int32, iLayerID);
            //db.AddInParameter(dbCommand, "iRegionID", DbType.Int32, iRegionID);
            //db.AddInParameter(dbCommand, "iCenterLngX", DbType.Double, iCenterLngX);
            //db.AddInParameter(dbCommand, "iCenterLatY", DbType.Double, iCenterLatY);
            //db.AddInParameter(dbCommand, "iMapObject", DbType.String, iMapObject);
            //db.AddInParameter(dbCommand, "iLatYmax", DbType.String, iNorth);
            //db.AddInParameter(dbCommand, "iLngXmax", DbType.String, iEast);
            //db.AddInParameter(dbCommand, "iLatYmin", DbType.String, iSouth);
            //db.AddInParameter(dbCommand, "iLngXmin", DbType.String, iWest);
            //using (IDataReader rdr = db.ExecuteReader(dbCommand))
            //{
            //    while (rdr.Read())
            //    {
            //        itemList.Add(RegionDTODataContract.DataContract(rdr));
            //    }
            //}

            return itemList;
        }

    }
}
